define(['jquery', 'bootstrap', 'backend', 'table', 'form','qrcode'], function ($, undefined, Backend, Table, Form,Qrcode) {


    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'information/inventoryclass/index' + location.search,
                    table: 'inventoryclass'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'cInvCName', title:'名称', operate: 'LIKE'},
                        {field: 'cInvCCode', title: '编码', operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), addclass:'datetimerange', autocomplete:false}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            $('.btn-danger').on('click',function(){
                Toastr.info("数据同步中请稍后....");
                $.post('information/inventoryclass/synData',function(e){
                    if(e.code==1){
                        Toastr.success(e.msg);
                        table.bootstrapTable('refresh');
                    }else{
                        Toastr.error(e.msg);
                    }
                })
            })


        },
        recyclebin: function () {
            // 为表格绑定事件
            Controller.api.bindevent();
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },

        choose:function(){
            $('#choose_id').click(function(){
                let id =  Controller.api.selectedids(chooseTable);
                Fast.api.close(id);
            })
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var chooseTable = $('#chooseTable')

            chooseTable.bootstrapTable({
                url: "information/warehouse/choose" + location.search,
                pk: 'id',
                search:false,
                singleSelect:true,
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'number', title: __('Number'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        //  {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        //  {field: 'switch', title: __('Switch'), searchList: {"0":__('Switch 0'),"1":__('Switch 1')}, table: table, formatter: Table.api.formatter.toggle},
                        {field: 'source', title: __('Source'), searchList: {"1":__('Source 1')," 2":__('Source  2')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(chooseTable);

        },
        api: {
            //获取选中的行
            selectedids: function (table, current) {
                var options = table.bootstrapTable('getOptions');
                //如果有设置翻页记忆模式
                if (!current && options.maintainSelected) {
                    return options.selectedIds;
                }
                return $.map(table.bootstrapTable('getSelections'), function (row) {
                    return row[options.pk];
                });
            },

            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
